<template>
  <el-dialog title="添加会员用户" :visible.sync="visible" width="800px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true">
      <el-form-item label="邮箱:" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称:" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table :data="userList" height="260px">
        <el-table-column label="序号" type="index" align="center" min-width="5%"/>
        <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
        <el-table-column label="昵称" prop="nickname" :show-overflow-tooltip="true" />
        <el-table-column label="头像" prop="avatar">
          <template slot-scope="scope">
            <image-preview class="list-img" :src="scope.row.avatar"/>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.member_account_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="注册时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="setVip(scope.row)"
              v-hasPermi="['system:memberVip:setVip']"
            >成为会员</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
  </el-dialog>
</template>

<script>
import { pageList,sysSetVip } from '@/api/triones/interlaceMember'
export default {
  dicts: ['member_account_status'],
  data() {
    return {
      visible: false,
      total: 0,
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isVip: '0',
        email: undefined,
        nickname: undefined
      }
    };
  },
  methods: {
    // 显示弹框
    show() {
      this.getList();
      this.visible = true;
    },
    // 查询表数据
    getList() {
      pageList(this.queryParams).then(res => {
        this.userList = res.rows;
        this.total = res.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 成为白标 */
    setVip(row) {
      this.$modal.confirm('是否确认将邮箱为"' + row.email + '"的用户设置为会员用户？').then(() => {
        sysSetVip(row.id,'sys_set').then(() => {
          this.getList();
          this.$emit("ok");
          this.$modal.msgSuccess("操作成功");
        });
      })
    }
  }
};
</script>
